package org.example.threadpool;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.example.utils.Sleeper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author zhengdp
 * @Description 线程池执行带返回结果的方法
 * @Date 2022/12/13 22:41
 * @Created by zhengdp
 */
@Slf4j(topic = "c.TestSubmit")
public class TestSubmit {
    @SneakyThrows
    public static void main(String[] args) {
        ExecutorService pool = Executors.newSingleThreadExecutor();
        Future<String> future = pool.submit(() -> {
            log.info("running");
            Sleeper.sleep(1000);
            return "ok";
        });
        log.info("{}",future.get());
    }
}
